import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/config/home_images.dart';
import 'package:juming_test/model/home/home_domain_model.dart';

class HomeDomainData extends StatelessWidget {
  const HomeDomainData({
    super.key,
    required this.domainData,
    required this.showAllData,
    required this.foldAction,
  });

  // 域名数据
  final HomeDomainModel? domainData;
  // 是否显示所有域名数据
  final bool showAllData;
  // 折叠域名数据
  final Function foldAction;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            _buildDomainData(domainData?.domainCount ?? 0, '我的域名'),
            _buildDomainData(domainData?.scheduleCount ?? 0, '我的预定'),
            _buildDomainData(domainData?.bidCount ?? 0, '我的竞价'),
            _buildDomainData(domainData?.renewCount ?? 0, '急需续费'),
          ],
        ),
        SizedBox(height: 16.w),
        Offstage(
          offstage: !showAllData,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              _buildDomainData(domainData?.waitPayCount ?? 0, '等待付款'),
              _buildDomainData(domainData?.onSellCount ?? 0, '正在出售'),
              SizedBox(width: 90.w),
              SizedBox(width: 90.w),
            ],
          ),
        ),
        SizedBox(
          height: 20.w,
          child: Center(
            child: IconButton(
              padding: EdgeInsets.zero,
              constraints: BoxConstraints(),
              onPressed: () => foldAction(),
              icon: Image.asset(
                !showAllData
                    ? HomeImages.homeHeaderArrowDownPng
                    : HomeImages.homeHeaderArrowUpPng,
                fit: BoxFit.cover,
              ),
            ),
          ),
        ),
      ],
    );
  }

  // 构建域名数据栏目数据
  Widget _buildDomainData(dynamic value, String title) {
    return SizedBox(
      width: 90.w,
      child: Column(
        children: [
          Text(
            "${value ?? 0}",
            style: TextStyle(
              fontSize: 24,
              fontWeight: FontWeight.bold,
              color: Colors.white,
            ),
          ),
          Text(title, style: TextStyle(color: Colors.white)),
        ],
      ),
    );
  }
}
